import * as ws from 'ws';

export class WClient{
    wc:WebSocket;
    constructor(url:string){
        this.wc = new WebSocket(url)
        this.wc.onopen = ()=>{
            this.onopen();
        }
        this.wc.onmessage = (e:MessageEvent)=>{
            this.onmessage(e.data);
        }
        this.wc.onerror=(ev: Event)=>{
            this.onerror(ev.type);
            this.wc.close();
        }
        this.wc.onclose = ()=>{
            this.onclose();
        }
    }

    onopen(){}
    onmessage(data:any){}
    onerror(err:string){}
    onclose(){}
}